<template>
	<view class="flex-container">
		<view>
			<!-- 提示信息弹窗 -->
			<uni-popup ref="message" type="message">
				<uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
			</uni-popup>
		</view>
		<view class="flex-item1 scroll-container" ref="scrollContainer">
			<view class="title flex-twice flex">
				<span class="title-left">排队工单列表({{leftNum}})</span>

				<yt-scanCode style="margin-top: 2%;margin-left: 22%;" btnName="扫码"
					@getScanCode="OnScanningCode"></yt-scanCode>
				<!-- <button class="bin-min bg-blue" @click="OnScanningCode">扫码</button> -->

			</view>
			<uni-search-bar :focus="true" v-model="searchValue" cancel-text="查询" @input="onInput" placeholder="MO查询"
				@cancel="cancel">
			</uni-search-bar>
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y">
				<view class="planlist" :class="setLeftItemColor(item)" v-for="(item,index) in procList "
					:key="item.jobId" @click="checkedProcsChange(item)">
					<div class="planlist-a">
						<span class="planlist-left">顺序:</span>
						<span class="planlist-right1">{{item.jobSerialNumber}}</span>
					</div>
					<div class="planlist-a">
						<span class="planlist-left">MO号: </span>
						<span class="planlist-right1">{{ item.mo }}&nbsp<span class="abnormal" v-if="item.abnormalFlag ===1">异常</span></span>
					</div>
					<div class="planlist-a">
						<span class="planlist-left">工序号: </span>
						<span class="planlist-right1">{{ item.jobCode }}</span>
					</div>
					<div class="planlist-a">
						<span class="planlist-left">工序: </span>
						<span class="planlist-right1"
							style="white-space: nowrap; overflow: hidden;text-overflow: ellipsis;">{{ item.jobName }}</span>
					</div>
					<div class="planlist-a">
						<span class="planlist-left">数量: </span>
						<span class="planlist-right2">{{item.jobPlanNum}}</span>
						<span class="planlist-left2">已加工数量: </span>
						<span class="planlist-right3">{{ item.jobActualAmount }}</span>
					</div>
					<div class="planlist-a">
						<span class="planlist-left">位置信息: </span>
						<span class="planlist-right1">{{ item.storeName }}</span>
					</div>
				</view>
			</scroll-view>
		</view>
		<view class="flex-item2">
			<view class="title">
				<span class="title-left">加工工单列表</span>
				<view class="flex  text-df list-left">
					<view class="flex-twice  radius">
						<view class="flex   justify-start text_hight ">
							<view class=" margin-df " style="margin-right:10upx;">MO号:</view>
							<view class=" margin-df ">{{workItem.mo}}&nbsp<span class="abnormal" v-if="workItem.abnormalFlag ===1">异常</span></view>
						</view>
					</view>
					<view class="flex-twice  radius ">
						<view class="flex   justify-start text_hight">
							<view class=" margin-df" style="margin-right:10upx;">图纸号码:</view>
							<view class=" margin-df ">{{workItem.th}}</view>
						</view>
					</view>
					<view class="flex-twice  radius ">
						<view class="flex   justify-start text_hight">
							<view class=" margin-df" style="margin-right:10upx;">工序名称:</view>
							<view class=" margin-df "
								style=" max-width:120px;white-space: nowrap; overflow: hidden;text-overflow: ellipsis;">
								{{ workItem.jobName }}
							</view>
						</view>
					</view>
				</view>
				<view class="flex  text-df list-top-left">
					<view class="flex-twice  radius">
						<view class="flex  justify-start text_hight">
							<view class=" margin-df" style="margin-right:10upx;">工序号:</view>
							<view class=" margin-df ">{{workItem.jobCode}}</view>
						</view>
					</view>
					<view class="flex-twice  radius">
						<view class="flex justify-start text_hight">
							<view class=" margin-df" style="margin-right:10upx;">版本号:</view>
							<view class=" margin-df ">{{workItem.thVersion}}</view>
						</view>
					</view>
					<view class="flex-twice radius">
						<view class="flex justify-start text_hight">
							<view class=" margin-df" style="margin-right:10upx;">开工时间:</view>
							<view class=" margin-df ">{{workItem.jobActualStartTime}}</view>
						</view>
					</view>
				</view>
				<view class="flex  text-df list-top-left">
					<view class="flex-twice  radius">
						<view class="flex  justify-start text_hight">
							<view class=" margin-df" style="margin-right:10upx;">计划数量:</view>
							<view class=" margin-df ">{{workItem.jobPlanNum}}</view>
						</view>
					</view>
					<view class="flex-twice  radius text_hight">
						<view class="flex justify-start">
							<view class=" margin-df" style="margin-right:10upx;">已加工数量:</view>
							<view class=" margin-df ">{{workItem.jobActualAmount}}</view>
						</view>
					</view>
					<view class="flex-twice radius">
						<view class="flex justify-start text_hight">
							<view class=" margin-df" style="margin-right:10upx;">上序报废数:</view>
							<view class=" margin-df ">{{workItem.preJobScrapNum}}</view>
						</view>
					</view>
				</view>

				<view>
					<v-tabs @change="changetab" ref="vTab" :tabs="tabs1" v-model="current" pills :fixed="false" style="border-top: 1px solid #dcdfe6;
					border-bottom: 1px solid #dcdfe6;" pillsBorderRadius='0rpx' pillsColor='#fff' activeColor='#2979ff' bgColor="#fff"
						:zIndex=0 :line-animation="false"></v-tabs>
					<view v-if="tab1">
						<uni-card>
							<view style="height:64vh">
								<view class="flex">
									<button class="bin-a bg-blue" @click="onCreateKzFile()">同步</button>
									<button class="bin-a bg-blue" @click="onWorkFile()">临时文件</button>
									<button class="bin-a bg-blue" @click="onhightFile()">高科技文件</button>
								</view>
								<!-- <uni-card style="background-color: #f2f2f2"> -->
								<scroll-view :scroll-top="scrollTop" scroll-y="true"
									style="height:54vh;background-color: #f2f2f2">
									<view v-for="(item,index) in Filelist ">
										<view style="padding-left: 1%;padding-top:4%;list-style-type : none;">
											<view style="font-size:20px" @click="fileLook(item.url)"><span
													style="font-size:20px">{{item.name}}</span>
											</view>
										</view>
									</view>
								</scroll-view>
								<!-- </uni-card> -->
							</view>
						</uni-card>
					</view>
					<view v-if="tab2">
						<uni-card>
							<view style="height:64vh">
								<zb-table :columns="column1" :stripe="true" :border="true" :data="data"></zb-table>
							</view>
						</uni-card>
					</view>
					<view v-if="tab3">
						<uni-card>
							<view style="height:64vh">
								<view class="cu-form-group" v-show="radio1">
									<view>
										<radio class='blue radio radio-left' :checked="true"></radio>
										<radio class='blue radio radio-left' :checked="true"></radio>
										<radio class='blue radio radio-left' :checked="true"></radio>
										<radio class='blue radio radio-left' :checked="true"></radio>
									</view>
								</view>
								<radio-group @change="RadioChange" v-show="radio2">
									<view class="cu-form-group radio-padd-bom">
										<view>
											<radio class='blue radio radio-first' :label="item.processTypeCode"
												v-for="(item, index) in bentypeList" :key="index" :checked="false"
												:value="item"> {{item.processTypeName }} </radio>
										</view>
									</view>
								</radio-group>
								<view class="redio-list">
									<radio-group @change="RadioChangeTwo" v-show="radio2">
										<view class="cu-form-group radio-padd-bom">
											<view>
												<radio class='blue radio radio-first' :label="item.processTypeCode"
													v-for="(item, index) in bentypeListTwo" :key="index"
													:checked="false" :value="item"> {{item.processTypeName }} </radio>
											</view>
										</view>
									</radio-group>
								</view>
								<view class="flex" style="margin-top: 1%;margin-bottom: 1%;">
									<view class="xiala">
										请选择处理人员：
									</view>
									<!-- 多选下拉菜单 - 使用默认的显示方式 -->
									<view class="xiala-list">
										<!-- <rudon-multiSelector welcome="请选择" :is_using_slot="false" :is_using_icon="true"
											:localdata="options" @change="whenChanged"></rudon-multiSelector> -->

										<zxz-uni-data-select v-model="value_select" collapse-tags multiple
											dataKey="text" dataValue="value" :localdata="options"
											@change="whenChanged"></zxz-uni-data-select>

									</view>
								</view>
								<view class="text-list flex">
									<view class="cu-form-group margin-top text-list-a">
										<textarea maxlength="-1" @input="textareaAInput"
											placeholder="请输入现象描述"></textarea>
									</view>
									<view class="text-bin-a">
										<button class="bin-a bg-blue" @click="handleSubmit()">发起</button>
									</view>
								</view>

							</view>
						</uni-card>
					</view>
					<view v-if="tab4">
						<uni-card>
							<view style="height:64vh">
								<zb-table @rowClick="rowClick" :cell-style="cellStyle" :columns="column3" :stripe="true"
									:border="true" :data="data3"></zb-table>
							</view>
						</uni-card>
					</view>
				</view>
			</view>
		</view>
		<view class="flex-item3">
			<view class="title ">
				<span class="title-left">扫码区域</span>
			</view>
			<view class="userlist">
				<div class="userlist-a">
					<span class="userlist-left">用户编码:</span>
					<span class="userlist-right1">{{loginUser_userCode}}</span>
				</div>
				<div class="userlist-a">
					<span class="userlist-left">用户名称:</span>
					<span class="userlist-right">{{loginUser_name}}</span>
				</div>
				<div class="userlist-a">
					<span class="userlist-left">登录时间:</span>
					<span class="userlist-right">{{loginUser_time}}</span>
				</div>
			</view>
			<view class="title" style="border-top: 1px solid #dcdfe6;	">
				<span class="title-left">按钮区域</span>
				<view class="buttonlist">
					<button class="button-a" @click="Task1()">现场接收</button>
					<button class="button-a" @click="Task2()">手动开工</button>
					<button class="button-a" @click="Task3()">手动完工</button>
					<button class="button-a" @click="Task4()">转移下序</button>
					<button class="button-a" :loading="Task5loading" @click="Task5()">反馈</button>
					<button v-if="ARShowFlag" class="button-b" @click="openThirdPartyApp()">AR</button>
					<button v-if="ARShowFlag===false" class="button-a" @click="openThirdPartyApp()">AR</button>
				</view>
			</view>
		</view>
		<view>
			<!-- 输入框示例 -->
			<uni-popup ref="inputDialog" type="dialog">
				<uni-popup-dialog ref="inputClose" mode="input" title="完工" value="" :before-close="true"
					placeholder="请输入完工数" @confirm="dialogInputConfirm" @close="dialogInputConfirmclose">
					<uni-forms ref="customForm" :rules="customRules" labelWidth="80px" :modelValue="customFormData">
						<uni-forms-item label="计划数量" name="jobPlanNum">
							<uni-easyinput v-model="customFormData.jobPlanNum" :disabled="true" placeholder="" />
						</uni-forms-item>
						<uni-forms-item label="投产数量" name="jobPrudctNum">
							<uni-easyinput v-model="customFormData.jobPrudctNum" :disabled="true" placeholder="" />
						</uni-forms-item>
						<uni-forms-item label="加工数量" name="jobActualAmount">
							<uni-easyinput v-model="customFormData.jobActualAmount" :disabled="true" placeholder="" />
						</uni-forms-item>
						<uni-forms-item label="报工数量" name="reportNum">
							<uni-easyinput v-model="customFormData.reportNum" placeholder="请输入报工数量" />
						</uni-forms-item>
					</uni-forms>
				</uni-popup-dialog>
			</uni-popup>
		</view>

	</view>
</template>
<script>
	// 获取 module
	const module = uni.requireNativePlugin("HuaweiScanModule-HuaweiScanModule")
	const modal = uni.requireNativePlugin('modal')
	import {
		getLeft,
		btnSelectLeftListByMo,
		getJobByJobId,
		createKzFile,
		listByJobId,
		listByParam,
		createUrl,
		configListByParam,
		partyListByParam,
		createProcess,
		getWebsocketUrl,
		confirmReviceTask,
		startWork,
		endWork,
		transfer,
		getViewPDF,
		findOrgCode,
		checkArGuid,
		dateFormat,
		bomFeedbackInfoItemSaveAllItemPolish
	} from '@/api/system/biaochu'
	import config from '@/config'
	export default {
		data() {
			return {
				Task5loading:false,
				ARShowFlag: true,
				msgType: '',
				messageText: '',
				Filelist: [],
				customFormData: {
					jobPlanNum: '', // 计划数量
					jobPrudctNum: '', //投产数量
					jobActualAmount: '', //已加工数量
					reportNum: '', //报工数量				
				},
				customRules: {
					reportNum: {
						rules: [{
							required: true,
							errorMessage: '报工数量不能为空'
						}, {
							format: 'number',
							errorMessage: '报工数量只能输入数字'
						}]
					}
				},
				msgType: "",
				messageText: "",
				radio1: true,
				radio2: false,
				mac: "", //获取Mac地址
				websocketUrl: "", //websocketUrl路径
				bentypeList: [], //异常反馈按钮第一排
				bentypeListTwo: [], //异常反馈按钮第二排
				textareaAValue: "", //异常反馈内容
				value_select: "", //选择处理人员
				bentypeListTwovalue: "", //第二排選中值
				bentypeListfirstvalue: "", //第一排選中值
				chuli: "", //处理
				websock: "", //websock
				options: [], // 处理人员
				loading: false, //
				scrollTop: 0, // 起始tab
				leftNum: "0", //排队工单列表数量
				loginUser_userCode: this.$store.state.user.userCode, //登录用户
				loginUser_name: this.$store.state.user.name, //登录用户
				loginUser_time: this.$store.state.user.time, //登录用户
				searchValue: "", //查询工单
				procList: [], //排队工单列表
				workItem: {}, //加工工单列表
				scanUsers: [], //刷卡用户
				current: 0,
				tab1: true,
				tab2: false,
				tab3: false,
				tab4: false,
				tabs1: [
					'工艺文件',
					'报工记录',
					'异常反馈',
					'反馈记录',
				],
				column3: [{
						label: '#',
						type: 'index',
						fixed: true,
						width: 60
					},
					{
						name: 'wwwwww',
						label: '操作',
						fixed: true,
						emptyString: '查看流程'
					},
					{
						name: 'processType',
						label: '流程类型',
						filters: {
							0: '工艺数据异常',
							1: '刀具异常',
							2: '设备故障',
							3: '加工过程停机'
						},
						width: 120
					},
					{
						name: 'partyName',
						label: '发起人',
					},
					{
						name: 'processStatus',
						label: '流程状态',
						filters: {
							0: '未开始',
							1: '已审批',
							2: '驳回'
						}
					},
					{
						name: 'lastDate',
						label: '上个节点处理时间',
						width: 200
					},
					{
						name: 'currentMode',
						label: '当前节点',
						filters: {
							1: '已接收',
							2: '处理完成'
						}
					},
					{
						name: 'reviewerPartyCode',
						label: '当前节点审批人',
						width: 150
					},
					{
						name: 'memo',
						label: '现象描述'
					},
					{
						name: 'plan',
						label: '驳回原因/解决方案',
						width: 150
					}
				], //反馈记录
				data3: [], //反馈记录数据
				data: [], //报工记录
				column1: [{
						name: 'userName',
						label: '人员姓名',
						emptyString: '--'
					},
					{
						name: 'reportNum',
						label: '报工数',
					},
					{
						name: 'timeStart',
						label: '开工时间',
						width: 120
					},
					{
						name: 'timeEnd',
						label: '报工时间',
						width: 120
					},
					{
						name: 'startSource',
						label: '开工数据源',
					},
					{
						name: 'reportSource',
						label: '报工数据源'
					},
				],

			}
		},
		created() {
			this.initLeft(); //按派工查询
			//this.initWebSocket() //初始化WebSocket
		},
		onLoad() {

		},
		//监听页面展示22
		onShow() {
			this.initWebSocket() //初始化WebSocket
		},

		onHide() {
			this.closeWebSocket()
			// module.unRegisterResultHandler();
		},
		methods: {
			OnScanningCode(res) {
				this.onInput(res);
				// module.scanForSingle();
				// console.log("4545工单查询 按钮 ", this.searchValue)

			},
			onInput(value) {
				// 这里的value就是输入框的当前值
				console.log(value);
				this.searchValue = value;
				this.Filelist = []
				this.ARShowFlag = true;
				this.radio1 = true;
				this.radio2 = false;
				if (this.searchValue === undefined || this.searchValue === '') {
					this.initLeft() //按派工查询
				} else {
					this.SelectLeftListByMo() //放开限制全体查询
				}
			},
			// 扫码注册
			registerResultHandler() {
				module.registerResultHandler(
					null,
					ret => {
						let {
							action,
							data
						} = ret

						switch (action) {
							case 'scan_for_single':
								this.searchValue = data
								break
							case 'scan_for_multi':
								this.searchValue = data
								break
							case 'register':
								// register success
								// modal.toast({message: '注册成功', duration: 1.5})
								break
							case 'unRegister':
								// unRegister success
								//  modal.toast({message: '注销成功', duration: 1.5})
								break
							case 'code':
								module.addRecord({
									sn: data,
									code: "ignore"
								})
								break
							case 'delete':
								// 半屏扫码删除一个记录会触发这个回调，sn 在 data 中 
								break
						}
					}
				)
			},
			// 是否有AR指导
			async onCheckArGuid() {
				let result = await checkArGuid(this.workItem.mateCode, this.workItem.jobCode)
				this.ARShowFlag = result !== 200;
				console.log(result)
			},
			// 打开AR指导
			openThirdPartyApp() {
				if (this.ARShowFlag) {
					uni.showToast({
						title: " 没有AR指导",
						icon: 'error',
						duration: 400
					})
				} else {
					// 判断是否安装了对应的APP
					if (plus.runtime.isApplicationExist({
							pname: 'com.DefaultCompany.ArprojectMes'
						})) {
						// 如果已安装，使用appUrlScheme打开APP
						plus.runtime.openURL(`unitydl://fcarmes?` + this.workItem.mo + `&` + this.workItem.mateCode + `&` +
							this.workItem.jobCode,
							function(error) {
								this.$modal.msgError(error.message)
							});
					} else {
						this.$modal.msgError("应用未安装")
					}
				}
			},
			// 文件查看
			fileLook(item) {
				if (item != "") {
					console.log("文件查看 ", item)
					uni.navigateTo({
						url: '/pages/web/pdf?fileurl=' + item
					})
				}
			},
			// 工单查询
			// OnScanningCode(res) {
			// 	console.log("4545工单查询 按钮 ", res)
			// 	this.searchValue = res;
			// 	this.Filelist = []
			// 	this.radio1 = true;
			// 	this.radio2 = false;
			// 	if (this.searchValue === undefined || this.searchValue === '') {
			// 		this.initLeft() //按派工查询
			// 	} else {
			// 		this.SelectLeftListByMo() //放开限制全体查询
			// 	}
			// },
			//工单查询
			cancel(res) {
				console.log("工单查询 按钮 ", res)
				this.searchValue = res.value;
				this.Filelist = []
				this.radio1 = true;
				this.radio2 = false;
				this.ARShowFlag = true;
				if (this.searchValue === undefined || this.searchValue === '') {
					this.initLeft() //按派工查询
				} else {
					this.SelectLeftListByMo() //放开限制全体查询
				}
			},
			//按派工查询
			initLeft() {
				this.workItem = {};
				let params = {};
				params.mo = this.searchValue;
				params.loginUser = this.$store.state.user.userAll;
				params.scanUserList = [];
				getLeft(params).then(res => {
					console.log("按派工查询", res)
					this.leftNum = res.data.length;
					this.procList = [];
					this.procList = res.data;
				}).catch(error => {
					reject(error)
				})
			},
			//放开限制全体查询
			SelectLeftListByMo() {
				var searchValue = this.searchValue;
				btnSelectLeftListByMo(searchValue).then(res => {
					console.log("放开限制全体查询", res);
					if (res === "") {
						this.$modal.msgError("该单号暂无工单")
					} else {
						this.leftNum = 1;
						this.procList = [];
						this.procList.push(res);
					}
				}).catch(error => {
					reject(error)
				})
			},
			//点击工单
			checkedProcsChange(item) {
				getJobByJobId(item.jobId).then(res => {
					console.log("点击工单", res.data)
					this.workItem = {};
					this.workItem = res.data;
					this.radio1 = false;
					this.radio2 = true;
					this.ViewPDF() // 获取文件
					this.onlistByJobId(); //报工记录
					this.onlistByParam(); //反馈记录
					this.configListByParam(); //异常反馈加载数据		
					this.onCheckArGuid(); //AR 指导 
				}).catch(error => {
					reject(error)
				})
			},

			// 获取文件
			ViewPDF() {
				if (Object.keys(this.workItem).length > 0) {
					this.Filelist = []
					findOrgCode().then(resh => {
						
						console.log("获取文件参数", this.workItem.th, this.workItem.thVersion, this.workItem
							.mo, this.workItem.mateCode, resh.data)
						getViewPDF(this.workItem.th, this.workItem.thVersion, this.workItem
							.mo, this.workItem.mateCode, resh.data).then(res => {
							console.log("获取文件",res)
							for (var i = 0; i < res.data.length; i++) {
								var firstfile = {
									name: '',
									url: ''
								};
								if (res.data[i].indexOf("</span></li>") != -1) {
									const start = "<span style=\"font-size:24px\">"
									const end = "</span></li>"
									const startIndex = res.data[i].indexOf(start) + start.length;
									const endIndex = res.data[i].indexOf(end, startIndex);
									firstfile.name = res.data[i].substring(startIndex, endIndex).myReplace(
										"&nbsp",
										"  ")
									firstfile.url = ""
								} else {
									var dataname = JSON.parse(JSON.stringify(res.data[i]))
									var dataurl = JSON.parse(JSON.stringify(res.data[i]))
									const start = "style=\"font-size:24px\">"
									const end = "</a></li>"
									const startIndex = dataname.indexOf(start) + start.length;
									const endIndex = dataname.indexOf(end, startIndex);
									firstfile.name = dataname.substring(startIndex, endIndex).myReplace(
										"&nbsp", "  ")
									const urlstart = "<a href=\""
									const urlend = "\" target=\"_blank\" style=\"font-size:24px\">"
									const urlstartIndex = dataurl.indexOf(urlstart) + urlstart.length;
									const urlendIndex = dataurl.indexOf(urlend, urlstartIndex);
									firstfile.url = dataurl.substring(urlstartIndex, urlendIndex).replace(
										"Views/mes/showpdf.html?url=", "")
								}

								this.Filelist.push(firstfile);
							}

							console.log("获取文件", this.Filelist)
						}).catch(error => {
							reject(error)
						})
					}).catch(error => {
						reject(error)
					})
				}
			},
			//切换tab
			changetab(res) {
				if (res === 0) {
					this.tab1 = true;
					this.tab2 = false;
					this.tab3 = false;
					this.tab4 = false;
				}
				if (res === 1) {
					this.tab1 = false;
					this.tab2 = true;
					this.tab3 = false;
					this.tab4 = false;
					this.onlistByJobId();
				}
				if (res === 2) {
					this.tab1 = false;
					this.tab2 = false;
					this.tab3 = true;
					this.tab4 = false;
					this.configListByParam(); //异常反馈加载数据
					this.bentypeListTwovalue = "";
					this.bentypeListfirstvalue = "";
					this.bentypeListTwo = [] //异常反馈按钮第二排
					this.textareaAValue = "" //异常反馈内容
					this.value_select = "" //选择处理人员
				}
				if (res === 3) {
					this.tab1 = false;
					this.tab2 = false;
					this.tab3 = false;
					this.tab4 = true;
					this.onlistByParam();
				}
			},
			//工艺文件-同步
			onCreateKzFile() {
				if (Object.keys(this.workItem).length === 0) {
					this.$modal.msgError("暂无工单")
				} else {
					this.$modal.loading("同步中，请耐心等待...")
					createKzFile(this.workItem.th, this.workItem.thVersion, this.workItem.mateCode).then(res => {
						console.log("工艺文件-同步", res)
						this.$modal.closeLoading();
						if (res.status === 200) {
							this.$modal.msgSuccess("同步成功")
						}
					}).catch(error => {
						this.$modal.closeLoading();
						reject(error)
					})
				}
			},
			//报工记录
			onlistByJobId() {
				if (Object.keys(this.workItem).length > 0) {
					listByJobId(this.workItem.jobId).then(res => {
						if (res.code === 200) {
							this.data = res.data;
						}
						console.log("报工记录", res)
					}).catch(error => {
						reject(error)
					})
				}
			},
			//异常反馈内容
			textareaAInput(e) {
				this.textareaAValue = e.detail.value
				console.log("异常反馈内容", e.detail.value)
			},
			//选择的处理人员
			whenChanged(e) {
				var a = "";
				console.log("选择的处理人员", JSON.stringify(e))
				this.chuli = "";
				if (e.length > 0) {
					for (let i = 0; i < e.length; i++) {
						a = a + e[i].value + ",";
					}
					this.chuli = a.substring(0, a.length - 1);
					console.log("选择的处理人员code", a.substring(0, a.length - 1))
				}
			},

			//工单背景颜色转变
			setLeftItemColor(item) {
				let priority = ""
				switch (item.jobPriority) {
					case "PLAN.t_plan_Job.Job_Priority.001":
						priority = "priority001"
						break
					case "PLAN.t_plan_Job.Job_Priority.002":
						priority = "priority002"
						break
					default:
						priority = ""
				}
				return priority
			},

			//反馈记录
			onlistByParam() {
				if (Object.keys(this.workItem).length > 0) {
					let data = {
						jobCode: this.workItem.mo
					}
					listByParam(data).then(res => {
						if (res.code === 200) {
							this.data3 = res.data;
						}
						console.log("反馈记录", res)
					}).catch(error => {
						reject(error)
					})
				}
			},
			//点击表格
			rowClick(row, index) {
				console.log('单击某行', row)
				createUrl(row.partyCode, row.id).then(res => {
					console.log('单击某行', res)
					if (res.data.code == 200) {
						console.log('单击某行web', res.data.data)
						uni.navigateTo({
							url: '/pages/web/webview?row=' + res.data.data
						})
					}

				}).catch(error => {
					reject(error)
				})
			},
			//表格颜色
			cellStyle({
				row,
				column,
				rowIndex,
				columnIndex
			}) {
				// console.log('row, column, rowIndex, columnIndex')
				if (columnIndex === 1) {
					return {
						color: '#409eff'
					}
				}
			},
			//异常反馈加载数据
			configListByParam() {
				var type = "机加工车间检验组";
				configListByParam(type, "", "").then(res => {
					console.log("异常反馈按钮", res)
					this.bentypeList = res.data;
					let filters = {};
					for (var i = 0; i < res.data.length; i++) {
						filters[res.data[i].processTypeCode] = res.data[i].processTypeName;
					}
					this.column3[2].filters = filters;
				})
			},
			//第一排点选框
			RadioChange(e) {
				this.bentypeListTwo = [] //异常反馈按钮第二排
				this.textareaAValue = "" //异常反馈内容
				this.value_select = "" //选择处理人员
				console.log("第一排点选radio", e.detail.value.processTypeCode)
				this.bentypeListfirstvalue = e.detail.value.processTypeCode;
				this.bentypeListTwo = [];
				var pid = e.detail.value.id;
				configListByParam("", pid, "").then(res => {
					console.log("第二排异常反馈按钮", res)
					this.bentypeListTwo = res.data;
				})
				var xialalist = [];
				partyListByParam(pid).then(res => {
					console.log("加载反馈人员信息", res)
					for (var i = 0; i < res.data.length; i++) {
						var xiala = {
							value: "",
							text: ""
						};
						xiala.value = res.data[i].partyCode;
						xiala.text = res.data[i].partyCode + "     " + res.data[i].partyName;
						xialalist.push(xiala)
					}
					console.log("下拉框內容", xialalist)
					this.options = xialalist;
				})
			},
			//第二排点选框
			RadioChangeTwo(e) {
				this.bentypeListTwovalue = e.detail.value.processTypeCode;
				console.log("第二排点选radio", e.detail.value.processTypeCode)
			},
			//提交異常反饋
			handleSubmit() {
				console.log("用戶信息", this.$store.state.user.userAll)
				console.log("请选择反馈异常", this.bentypeListfirstvalue)
				var a = "";
				let bentypeListfirstvalue = this.bentypeListfirstvalue;
				let bentypeListTwovalue = this.bentypeListTwovalue;
				if (bentypeListfirstvalue == "") {
					this.$modal.msgError("请选择反馈异常")
					return;
				}
				if (bentypeListTwovalue == "") {
					this.$modal.msgError("请选择异常分类")
					return;
				}
				if (this.chuli === "" || this.chuli === undefined) {
					this.$modal.msgError("请选择处理人员")
					return;
				}

				let data = {
					processType: this.bentypeListfirstvalue,
					partyName: this.$store.state.user.userAll.userName,
					partyCode: this.$store.state.user.userAll.userCode,
					reviewerPartyCode: this.chuli,
					jobCode: this.workItem.mo,
					procCode: this.workItem.jobCode,
					procId: this.workItem.jobId,
					memo: this.textareaAValue,
					processChildType: this.bentypeListTwovalue,
					productionType: "表处"
				}
				console.log("异常反馈信息", data);
				createProcess(data).then(res => {
					console.log(res)
					this.$modal.msgSuccess(res.msg)
				})
			},
			//获取设备的mac地址
			getDeviceMac() {
				//获取本机Mac地址
				var deviceMac = '';
				var net = plus.android.importClass('java.net.NetworkInterface');
				var wl0 = net.getByName('wlan0');
				var macByte = wl0.getHardwareAddress();
				deviceMac = '';
				for (var i = 0; i < macByte.length; i++) {
					var tmp = '';
					var num = macByte[i];
					if (num < 0) {
						tmp = (255 + num + 1).toString(16);
					} else {
						tmp = num.toString(16);
					}
					if (tmp.length == 1) {
						tmp = '0' + tmp;
					}
					deviceMac += tmp;
				}
				return deviceMac;
			},
			/*websocek网址路径*/
			async initWebsocketUrl() {
				let result = await getWebsocketUrl()
				this.websocketUrl = result.data
				console.log("new websocketUrl", this.websocketUrl)
			},
			/*websocek处理*/
			async initWebSocket() {
				this.mac = this.getDeviceMac();
				console.log("new mac", this.mac)
				var macurl = this.mac;
				await this.initWebsocketUrl()
				var socketTask = uni.connectSocket({
					url: this.websocketUrl, //仅为示例，并非真实接口地址。
				});
				let msg = {
					"code": 0,
					"msg": '这是client：初次连接',
					"sid": macurl, //设置表处 操作电脑的sid
				}
				console.log('msg', JSON.stringify(msg));
				let msgString = JSON.stringify(msg);
				uni.onSocketOpen(function(res) {
					console.log('WebSocket连接已打开！');
					uni.sendSocketMessage({
						data: msgString
					});
				});
				uni.onSocketError(function(res) {
					console.log('WebSocket连接打开失败，请检查！');
				});
				var that = this;
				uni.onSocketMessage(function(res) {
					let messageData = JSON.parse(res.data);
					console.log('收到服务器内容：', messageData);
					if (messageData.type != null) {
						if (messageData.type === "user") { //扫描用户
							that.handleSocketUser(messageData)
						}
						if (messageData.type === "job") { //扫描工单
							that.handleSocketMo(messageData)
						}
					}
				});
			},
			//  扫描工单
			handleSocketMo(messageData) {
				// this.msgType = 'success';
				// this.messageText = `收到一条新的工序消息`
				// this.$refs.message.open()
				var jobId = messageData.job.jobId;
				if (messageData.status === "1") {
					this.procList = [];
					// console.log('收到扫描工单：', messageData);
					let jobId = messageData.job.jobId
					let kkk = {
						jobId: jobId
					}
					//加载工序
					console.log('收到扫描工单：', kkk)
					this.checkedProcsChange(kkk);
				} else {
					if (this.workItem.jobId === jobId) {
						this.workItem = {}
						this.data = []
						this.textareaAValue = ""
						this.chuli = ""
						this.data3 = []
						this.bentypeListTwo = {}
						this.options = {}
						this.bentypeList = {}
						this.Filelist = [],
							this.bentypeListfirstvalue = {}
						this.radio1 = true
						this.radio2 = false
					}
				}
			},
			// 用户赋值
			handleSocketUser(messageData) {
				if (messageData.status === "1") {
					console.log('收到服务器内容用户：', messageData);
					if (messageData.user.partyCode === this.loginUser_userCode && messageData.user.partyName === this
						.loginUser_userName) {

					} else {
						this.scanUsers = [];
						this.loginUser_userCode = messageData.user.partyCode;
						this.loginUser_name = messageData.user.partyName;
						this.loginUser_time = this.NyrTime();
						this.scanUsers.push(messageData.user)
					}
				} else {
					//删除用户
					this.loginUser_userCode = this.$store.state.user.userCode; //登录用户
					this.loginUser_name = this.$store.state.user.name; //登录用户
					this.loginUser_time = this.$store.state.user.time; //登录用户
					let delUser = messageData.user
					if (this.scanUsers.length > 0) {
						if (this.scanUsers.partyCode === delUser.partyCode) {
							this.scanUsers = [];
						}
					}
				}
			},
			//获取年月日
			NyrTime() {
				const date = new Date();
				var hours = date.getHours();
				var minutes = date.getMinutes();
				var seconds = date.getSeconds();
				hours = hours < 10 ? '0' + hours : hours;
				minutes = minutes < 10 ? '0' + minutes : minutes;
				seconds = seconds < 10 ? '0' + seconds : seconds;
				const time = hours + ":" + minutes + ":" + seconds
				return time;
			},
			//关闭 WebSocket
			closeWebSocket() {
				uni.closeSocket();
				console.log('WebSocket 已关闭！');
			},
			//提交工单用户
			reportUsers() {
				var reportUser = '';
				if (this.scanUsers.length > 0) {
					reportUser = this.scanUsers.partyCode;
				} else {
					reportUser = this.$store.state.user.userCode;
				}
				return reportUser
			},
			// 刷新工序
			refreshWorkList() {
				getJobByJobId(this.workItem.jobId).then(res => {
					console.log("刷新工序", res.data)
					this.workItem = {};
					this.workItem = res.data;
				}).catch(error => {
					reject(error)
				})
			},
			//现场接收
			Task1() {
				console.log(this.workItem)
				if (Object.keys(this.workItem).length === 0) {
					this.$modal.msgError(`没有工单!`)
					return
				}
				console.log(this.workItem.stutStatecode)
				// PLAN.t_plan_Job.STUT_StateCode.014 加工中
				// PLAN.t_plan_Job.STUT_StateCode.018 已完成
				if (this.workItem.stutStatecode === 'PLAN.t_plan_Job.STUT_StateCode.014' || this.workItem.stutStatecode ===
					'PLAN.t_plan_Job.STUT_StateCode.018') {
					this.$modal.msgError("没有接收的工单");
					return
				}
				const userCode = this.reportUsers();
				let data = {}
				data.tprocId = this.workItem.jobId
				data.jobCode = this.workItem.jobCode
				data.jobId = this.workItem.jobPid
				data.jobPrudctnum = this.workItem.jobPrudctNum
				console.log("现场接收:", data, userCode)
				//调用现场接收接口
				uni.showLoading({
					title: '数据处理中……'
				});
				let res = confirmReviceTask(data, userCode)
				console.log(res)
				uni.hideLoading();
				if (res.code === 200) {
					//接收成功需要修改数据状态	
					this.refreshWorkList();
					this.$modal.msgSuccess(res.msg);
				}


			},
			//手动开工
			Task2() {
				if (Object.keys(this.workItem).length === 0) {
					this.$modal.msgError(`没有工单!`)
					return
				}
				//判断如果有状态未接收需要提示
				if (this.workItem.stutStatecode !== 'PLAN.t_plan_Job.STUT_StateCode.014' && this.workItem.stutStatecode !==
					'PLAN.t_plan_Job.STUT_StateCode.018') {
					this.$modal.msgError("请先接受工单");
					return
				}

				if (this.workItem.stutStatecode !== 'PLAN.t_plan_Job.STUT_StateCode.018') {
					let data = {}
					let needWorkList = [];
					needWorkList.push(this.workItem);
					data.reportJobDtos = needWorkList;
					data.loginUser = this.$store.state.user.userAll
					data.scanUserList = this.scanUsers
					console.log("手动开工数据", data)
					uni.showLoading({
						title: '数据处理中……'
					});
					startWork(data).then(res => {
						uni.hideLoading();
						if (res.data === '开工成功') {
							this.$modal.msgSuccess("开工成功")
							this.refreshWorkList();
						}
					})
				} else {
					this.$modal.msgError("工单已完成！")
				}
			},
			//手动完工
			Task3() {
				if (Object.keys(this.workItem).length === 0) {
					this.$modal.msgError(`没有工单!`)
					return
				}
				if (this.workItem.stutStatecode !== 'PLAN.t_plan_Job.STUT_StateCode.014' && this.workItem.stutStatecode !==
					'PLAN.t_plan_Job.STUT_StateCode.018') {
					this.$modal.msgError(`请先现场接收!`)
					return
				}
				this.customFormData.jobPlanNum = this.workItem.jobPlanNum; // 计划数量
				this.customFormData.jobPrudctNum = this.workItem.jobPrudctNum; // 投产数量
				this.customFormData.jobActualAmount = this.workItem.jobActualAmount; // 已加工数量
				this.$refs.inputDialog.open()
			},
			//提交手动完工数
			dialogInputConfirm(val) {
				//获取填写报工数量的数据提交
				let data = {};
				var reportUserk = JSON.parse(JSON.stringify(this.$store.state.user.userAll));
				if (this.scanUsers.length > 0) {
					reportUserk.userId = this.scanUsers[0].partyId
					reportUserk.userName = this.scanUsers[0].partyName
					reportUserk.userCode = this.scanUsers[0].partyCode
				}
				this.$refs["customForm"].validate().then(res => {
					this.workItem.reportNum = this.customFormData.reportNum;
					var reportJobDtos = [];
					reportJobDtos.push(this.workItem)
					data.reportJobDtos = reportJobDtos;
					data.reportUser = reportUserk;
					console.log("手动完工", data)
					uni.showLoading({
						title: '数据处理中……'
					});
					endWork(data).then(res => {
						uni.hideLoading();
						if (res.data === '报工成功') {
							this.$refs.inputDialog.close();
							this.customFormData.reportNum = "";
							this.refreshWorkList();
							this.$modal.msgSuccess("报工成功")

						} else {
							this.msgType = "error"
							this.messageText = res.data
							this.$refs.message.open()
						}
					})
				}).catch(err => {
					return
				})
			},
			// 关闭手动完工弹出框
			dialogInputConfirmclose() {
				this.customFormData.reportNum = "";
				this.$refs.inputDialog.close();
			},
			// 转移下序
			Task4() {
				if (Object.keys(this.workItem).length === 0) {
					this.$modal.msgError(`没有工单!`)
					return
				}
				if (this.workItem.stutStatecode !== 'PLAN.t_plan_Job.STUT_StateCode.014' && this.workItem.stutStatecode !==
					'PLAN.t_plan_Job.STUT_StateCode.018') {
					this.$modal.msgError(`请先现场接收!`)
					return
				}
				uni.showLoading({
					title: '数据处理中……'
				});
				var reportJobDtos = [];
				reportJobDtos.push(this.workItem)
				let data = {}
				data.reportJobDtos = reportJobDtos
				data.loginUser = JSON.parse(JSON.stringify(this.$store.state.user.userAll))
				data.scanUserList = this.scanUsers
				transfer(data).then(res => {
					uni.hideLoading();
					if (res.data === '转移成功') {
						this.refreshWorkList();
						this.$modal.msgSuccess("转移成功")
					} else {
						this.msgType = "error"
						this.messageText = res.data
						this.$refs.message.open()
					}
				})

			},
			//临时文件
			onWorkFile() {
				var file = "%5C%5C192.168.10.254%5Cshare%5C%5Cprograms%5CLINSHI_NEW"
				uni.navigateTo({
					url: '/pages/work/directory?url=' + file
				})
			},
			//高科技文件
			onhightFile() {
				var file = "%5C%5C192.168.10.254%5Cshare%5C%5Cprograms%5CHK"
				uni.navigateTo({
					url: '/pages/work/directory?url=' + file
				})
			},
			//异常反馈
			Task5() {
				this.Task5loading=true;
				var that = this;
				if (Object.keys(this.workItem).length === 0) {
					this.$modal.msgError(`没有工单!`)
					this.Task5loading=false;
					return
				} else {
					let backInfo = {
						id: "",
						workJobId: "",
						paramOfTechnical: {},
						exceptionHandleTypeCode: "",
						userInfo: {
							userId: "",
							userName: "",
							code: ""
						}
					}
					var data = JSON.parse(JSON.stringify(that.workItem));
					let userInfo = {
						userId: "",
						userName: "",
						code: ""
					};
					if (this.scanUsers.length > 0) {
						userInfo.userName = this.scanUsers[0].partyName
						userInfo.userId = this.scanUsers[0].partyId
						userInfo.code = this.scanUsers[0].partyCode
					} else {
						userInfo.userName = this.$store.state.user.userAll.userName;
						userInfo.userId = this.$store.state.user.userAll.userId
						userInfo.code = this.$store.state.user.userAll.userCode
					}
					let techniqueName = ''
					if (data.jobEqname != null) {
						if (data.jobEqname.includes('焊接')) {
							techniqueName = '焊接工艺'
						} else if (data.jobEqname.includes('车床')) {
							techniqueName = '车床工艺'
						} else if (data.jobEqname.includes('铣床')) {
							techniqueName = '铣床工艺'
						} else if (data.jobEqname.includes('表处')) {
							techniqueName = '表处工艺'
						} else {
							techniqueName = ''
						}
					}
					let paramOfTechnical = {
						//物料编码
						materielNum: data.mateCode,
						//materielNum:'M0201-103966',
						//组织
						productionOrganization: '沈阳',
						//工段
						techniqueName: techniqueName,
						jobId: data.jobId,
						moCode: data.mo,
					}
					backInfo.paramOfTechnical = paramOfTechnical;

					let params = {
						jobId: data.jobId,
						patycode: userInfo.userId,
						equiId: data.jobEqId,
						findRenYuan: userInfo.userName,
						findDate: dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss'),
						shebei: data.jobEqname,
						//物料编码
						materielNum: data.mateCode,
						//组织
						productionOrganization: '沈阳',
						//工段
						techniqueName: '',
						systemCode: "NEW",
						abnormalSendType: "BASE",
					};
					//console.log(params);
					bomFeedbackInfoItemSaveAllItemPolish(params).then(res => {
						//  console.log(res)
						if (res.code === 200) {
							backInfo.id = res.data.id;
							backInfo.workJobId = res.data.workJobId;
							backInfo.exceptionHandleTypeCode = res.data.exceptionHandleTypeCode;
							backInfo.userInfo = userInfo;
							// console.log(backInfo)
							this.Task5loading=false;
							uni.navigateTo({
								url: '/pages/fankui/index?parme=' + JSON.stringify(backInfo)
							})
						} else {
							this.Task5loading=false;
							this.$modal.msgError(`读取异常失败`)
						}
						this.Task5loading=false;
					})
                   
				}
			}
		}

	}
</script>

<style lang="scss">
	.radio-first {
		padding-right: 20upx;
		padding-top: 20upx;
	}

	.radio-padd-bom {
		padding-bottom: 20upx;
	}

	.text-list {
		border: 1px solid #EBEEF5;
		border-right: none;
		border-left: none;
	}

	.text-bin-a {
		margin: 5%;
	}

	.text-list-a {
		border: 1px solid #EBEEF5;
		width: 50%;
		margin: 2%;
	}

	.redio-list {
		border: 1px solid #EBEEF5;
		border-right: none;
		border-left: none;
		padding: 10px;
	}

	.xiala-list {

		width: 50%;
		line-height: 60rpx;
		text-align: left;
		font-size: 38rpx;
		font-weight: 500;
	}

	.xiala {
		margin-left: 5%;
		line-height: 60rpx;
		text-align: left;
		font-size: 38rpx;
		font-weight: 500;
	}

	.radio-left {
		margin-left: 30upx;
	}

	.priority001 {
		background-color: rgba(255, 0, 0, 0.3);
	}

	.priority002 {
		background-color: rgba(255, 255, 0, 0.3);
	}

	.bin-a {
		display: inline-block;
		margin: 5px 0 5px 10px;
		height: 50px;
		width: 120px;
		text-align: center;
		background: #409eff;
		line-height: 50px;
		color: #fff;
		border-radius: 3px;
		cursor: pointer;
	}

	.bin-min {
		height: 30px;
		width: 70px;
		margin-top: 2%;
		margin-left: 20%;
		text-align: center;
		background: #409eff;
		line-height: 30px;
		color: #fff;
	}

	::v-deep {
		.uni-card {
			margin: 8px !important;
			padding: 0 !important;

			.uni-card__content {
				padding: 0 !important;
			}
		}
	}

	.list-left {
		margin-left: 25upx;
		//margin-bottom: 15upx;
		//font-weight: 700;
	}

	.list-top-left {
		margin-top: -10upx;
		margin-left: 25upx;
		//margin-bottom: 15upx;
		// font-weight: 700;
	}

	.scroll-Y {
		height: 950rpx;
	}

	.planlist-right2 {
		margin-left: 5rpx;
	}

	.planlist-left2 {
		margin-left: 60rpx;
	}

	.planlist-right3 {
		margin-left: 5rpx;
	}

	.planlist-a {
		line-height: 40rpx;
		font-size: 30rpx;
		margin-top: 5rpx;
	}

	.planlist-left {
		float: left;
		text-align: right;
		width: 30%;
		height: 40rpx;
	}

	.planlist-right1 {
		margin-left: 5rpx;
		float: right;
		width: 67%;
		height: 40rpx;
	}

	.userlist-a {
		line-height: 40rpx;
		font-size: 30rpx;
		margin-top: 10rpx;
		margin-left: 10%;
	}

	.userlist-left {
		float: left;
		width: 43%;
		height: 22px;
	}

	.userlist-right {
		float: right;
		width: 57%;
		height: 22px;
	}

	.buttonlist {
		margin-top: 10rpx;
	}

	.button-a {
		margin: 6px;
		background-color: #007aff;
		width: 90%;
		margin-left: 5%;
		color: #fff;
	}

	.button-b {
		margin: 6px;
		background-color: #4b5563;
		width: 90%;
		margin-left: 5%;
		color: #fff;
	}

	.planlist {
		margin-bottom: 10rpx;
		height: 300rpx;
		padding: 10rpx;
		font-size: 14rpx;
		//font-weight: 700;
		color: #111;
		border: 1px solid #dcdfe6;
		width: 95%;
		margin-top: 5rpx;
		margin-left: 2.5%;
		-webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1), 0 0 6px 0 rgba(0, 0, 0, .04);
		box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1), 0 0 6px 0 rgba(0, 0, 0, .04);
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		border-radius: 5px;
	}

	.userlist {
		margin-bottom: 10rpx;
		height: 87.5px;
		padding: 10rpx;
		font-size: 14rpx;
		//font-weight: 700;
		color: #111;
		border: 1px solid #dcdfe6;
		width: 95%;
		margin-top: 5rpx;
		margin-left: 2.5%;
		-webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1), 0 0 6px 0 rgba(0, 0, 0, .04);
		box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1), 0 0 6px 0 rgba(0, 0, 0, .04);
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
	}

	.title-left {
		margin-left: 20rpx;
	}

	.title {
		background-color: #ffffff;
		height: 86.6rpx;
		line-height: 86.6rpx;
		text-align: left;
		font-size: 36rpx;
		color: #111;
		border-bottom: 1px solid #dcdfe6;
	}

	.flex-container {
		display: flex;
		justify-content: space-between;
		// margin-top: 45rpx;
	}

	.flex-item1 {
		width: 24%;
		height: 98vh;
		margin: 0.5%;
		background-color: #ffffff;
		border: 1px solid #dcdfe6;
	}

	.flex-item2 {
		background-color: #ffffff;
		height: 98vh;
		width: 56%;
		margin: 0.5%;
		border: 1px solid #dcdfe6;
	}

	.flex-item3 {
		background-color: #ffffff;
		height: 98vh;
		width: 17%;
		margin: 0.5%;
		border: 1px solid #dcdfe6;
	}

	.text_hight {
		line-height: 35px;
	}
	.abnormal{
	  color: rgba(246, 70, 5, 0.98)
	}

</style>